add a wizard page to check terms of service
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 17 Feb 2025 10:49:35 +0000 (11:49 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 20 Feb 2025 11:00:54 +0000 (12:00 +0100)
should enable proper polling while the user check and signs the terms of
service via teh web browser

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
src/gui/CMakeLists.txt
src/gui/wizard/flow2authcredspage.cpp
src/gui/wizard/owncloudwizard.cpp
src/gui/wizard/owncloudwizard.h
src/gui/wizard/owncloudwizardcommon.h
src/gui/wizard/termsofservicewizardpage.cpp [new file with mode: 0644]
src/gui/wizard/termsofservicewizardpage.h [new file with mode: 0644]
src/gui/wizard/webviewpage.cpp

index 4bd77fabad29464389f045a7e41a1472d43b6394..5bb37c6ce905cc41dd0e3cba712fdc01b173b7d6 100644 (file)
@@ -240,6 +240,8 @@ set(client_SRCS
     wizard/flow2authwidget.cpp
     wizard/owncloudsetuppage.h
     wizard/owncloudsetuppage.cpp
+    wizard/termsofservicewizardpage.h
+    wizard/termsofservicewizardpage.cpp
     wizard/owncloudwizardcommon.h
     wizard/owncloudwizardcommon.cpp
     wizard/owncloudwizard.h
index e03b9a50faba5a1a1978cf597d0259b48310b852..a2f23f6ef2631b589b70b405d643d279923d7562 100644 (file)
@@ -104,7 +104,7 @@ void Flow2AuthCredsPage::slotFlow2AuthResult(Flow2Auth::Result r, const QString
 
 int Flow2AuthCredsPage::nextId() const
 {
-    return WizardCommon::Page_AdvancedSetup;
+    return WizardCommon::Page_TermsOfService;
 }
 
 void Flow2AuthCredsPage::setConnected()
index 9368b3d162800f3a09f2973d45698e77aa744ce7..4fb364b8f4fb23e5980b2dcc635c731c630df5a1 100644 (file)
@@ -27,6 +27,7 @@
 #include "wizard/welcomepage.h"
 #include "wizard/owncloudsetuppage.h"
 #include "wizard/owncloudhttpcredspage.h"
+#include "wizard/termsofservicewizardpage.h"
 #include "wizard/owncloudadvancedsetuppage.h"
 #include "wizard/webviewpage.h"
 #include "wizard/flow2authcredspage.h"
@@ -239,9 +240,12 @@ void OwncloudWizard::setRemoteFolder(const QString &remoteFolder)
 
 void OwncloudWizard::successfulStep()
 {
-    const int id(currentId());
+    const WizardCommon::Pages id{static_cast<WizardCommon::Pages>(currentId())};
 
     switch (id) {
+    case WizardCommon::Page_Welcome:
+        break;
+
     case WizardCommon::Page_HttpCreds:
         _httpCredsPage->setConnected();
         break;
@@ -258,6 +262,10 @@ void OwncloudWizard::successfulStep()
         break;
 #endif // WITH_WEBENGINE
 
+    case WizardCommon::Page_TermsOfService:
+        _termsOfServicePage->initializePage();
+        break;
+
     case WizardCommon::Page_AdvancedSetup:
         _advancedSetupPage->directoriesCreated();
         break;
@@ -351,7 +359,13 @@ void OwncloudWizard::slotCurrentPageChanged(int id)
 
 void OwncloudWizard::displayError(const QString &msg, bool retryHTTPonly)
 {
-    switch (currentId()) {
+    switch (static_cast<WizardCommon::Pages>(currentId())) {
+    case WizardCommon::Page_Welcome:
+    case WizardCommon::Page_Flow2AuthCreds:
+    case WizardCommon::Page_WebView:
+    case WizardCommon::Page_TermsOfService:
+        break;
+
     case WizardCommon::Page_ServerSetup:
         _setupPage->setErrorString(msg, retryHTTPonly);
         break;
index da614b92d7e5cba60ba100b7fc00c05a36c1c56d..7f950db06493f63ae4ca17c4641d6ed7128d370c 100644 (file)
@@ -33,6 +33,7 @@ Q_DECLARE_LOGGING_CATEGORY(lcWizard)
 class WelcomePage;
 class OwncloudSetupPage;
 class OwncloudHttpCredsPage;
+class TermsOfServiceWizardPage;
 class OwncloudAdvancedSetupPage;
 class OwncloudWizardResultPage;
 class AbstractCredentials;
@@ -123,14 +124,15 @@ private:
     [[nodiscard]] QList<QSize> calculateWizardPageSizes() const;
 
     AccountPtr _account;
-    WelcomePage *_welcomePage;
-    OwncloudSetupPage *_setupPage;
-    OwncloudHttpCredsPage *_httpCredsPage;
-    Flow2AuthCredsPage *_flow2CredsPage;
-    OwncloudAdvancedSetupPage *_advancedSetupPage;
+    WelcomePage *_welcomePage = nullptr;
+    OwncloudSetupPage *_setupPage = nullptr;
+    OwncloudHttpCredsPage *_httpCredsPage = nullptr;
+    Flow2AuthCredsPage *_flow2CredsPage = nullptr;
+    TermsOfServiceWizardPage *_termsOfServicePage = nullptr;
+    OwncloudAdvancedSetupPage *_advancedSetupPage = nullptr;
     OwncloudWizardResultPage *_resultPage = nullptr;
     AbstractCredentialsWizardPage *_credentialsPage = nullptr;
-    WebViewPage *_webViewPage = nullptr;
+    WebViewPage*_webViewPage = nullptr;
 
     QStringList _setupLog;
 
index f5d7ba530f436fc2ae87b7067352f14c8bc923bd..7c771492052daa1fd376016338c6ecb79006c194 100644 (file)
@@ -50,6 +50,7 @@ namespace WizardCommon {
 #ifdef WITH_WEBENGINE
         Page_WebView,
 #endif // WITH_WEBENGINE
+        Page_TermsOfService,
         Page_AdvancedSetup,
     };
 
diff --git a/src/gui/wizard/termsofservicewizardpage.cpp b/src/gui/wizard/termsofservicewizardpage.cpp
new file mode 100644 (file)
index 0000000..5a7ec7a
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) by Matthieu Gallien <matthieu.gallien@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "termsofservicewizardpage.h"
+
+#include "account.h"
+#include "owncloudsetupwizard.h"
+#include "wizard/owncloudwizard.h"
+#include "wizard/owncloudwizardcommon.h"
+#include "connectionvalidator.h"
+
+#include <QVBoxLayout>
+#include <QDesktopServices>
+
+namespace OCC {
+
+OCC::TermsOfServiceWizardPage::TermsOfServiceWizardPage()
+    : QWizardPage()
+{
+    _layout = new QVBoxLayout(this);
+}
+
+void OCC::TermsOfServiceWizardPage::initializePage()
+{
+}
+
+void OCC::TermsOfServiceWizardPage::cleanupPage()
+{
+}
+
+int OCC::TermsOfServiceWizardPage::nextId() const
+{
+    return WizardCommon::Page_AdvancedSetup;
+}
+
+bool OCC::TermsOfServiceWizardPage::isComplete() const
+{
+    return false;
+}
+
+void TermsOfServiceWizardPage::slotPollNow()
+{
+    _termsOfServiceChecker = new TermsOfServiceChecker{_ocWizard->account(), this};
+
+    connect(_termsOfServiceChecker, &TermsOfServiceChecker::done, this, &TermsOfServiceWizardPage::termsOfServiceChecked);
+    _termsOfServiceChecker->start();
+}
+
+void TermsOfServiceWizardPage::termsOfServiceChecked()
+{
+    if (_termsOfServiceChecker && _termsOfServiceChecker->needToSign()) {
+        QDesktopServices::openUrl(_ocWizard->account()->url());
+    } else {
+        _ocWizard->successfulStep();
+        delete _termsOfServiceChecker;
+        _termsOfServiceChecker = nullptr;
+    }
+}
+
+}
diff --git a/src/gui/wizard/termsofservicewizardpage.h b/src/gui/wizard/termsofservicewizardpage.h
new file mode 100644 (file)
index 0000000..86765e2
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) by Matthieu Gallien <matthieu.gallien@nextcloud.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef TERMSOFSERVICEWIZARDPAGE_H
+#define TERMSOFSERVICEWIZARDPAGE_H
+
+#include <QWizardPage>
+
+class QVBoxLayout;
+
+namespace OCC {
+
+class OwncloudWizard;
+class TermsOfServiceChecker;
+
+class TermsOfServiceWizardPage : public QWizardPage
+{
+    Q_OBJECT
+public:
+    TermsOfServiceWizardPage();
+
+    void initializePage() override;
+    void cleanupPage() override;
+    [[nodiscard]] int nextId() const override;
+    [[nodiscard]] bool isComplete() const override;
+
+Q_SIGNALS:
+    void connectToOCUrl(const QString &);
+    void pollNow();
+
+private Q_SLOTS:
+    void slotPollNow();
+    void termsOfServiceChecked();
+
+private:
+    QVBoxLayout *_layout = nullptr;
+    OwncloudWizard *_ocWizard = nullptr;
+    TermsOfServiceChecker *_termsOfServiceChecker = nullptr;
+};
+
+} // namespace OCC
+
+#endif // TERMSOFSERVICEWIZARDPAGE_H
index 18acab0c44e7f9900f9a646258276bcea1432c28..a3587d1d8e3b07a7ec8fc303b8ce7eb20bd82bf1 100644 (file)
@@ -92,7 +92,7 @@ void WebViewPage::cleanupPage()
 }
 
 int WebViewPage::nextId() const {
-    return WizardCommon::Page_AdvancedSetup;
+    return WizardCommon::Page_TermsOfService;
 }
 
 bool WebViewPage::isComplete() const {